﻿using System.Security.Claims;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace FDSimpleModelGenerator.Common.Mvc.PageModels
{
    public class BasicModel : PageModel
    {
        public string UserName { get; private set; }
        public int UserId { get; private set; }

        public override void OnPageHandlerExecuting(PageHandlerExecutingContext context)
        {
            if (context.HttpContext.User.Identity.IsAuthenticated)
            {
                var user = context.HttpContext.User;
                UserName = user.Identity.Name;
                var sid = user.FindFirst(ClaimTypes.Sid)?.Value;
                int.TryParse(sid, out int userId);
                UserId = userId;
            }
            base.OnPageHandlerExecuting(context);
        }
    }
}
